package com.kgc.rb.controller;

import com.kgc.rb.common.tools.ActiveMQTools;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.JMSException;

@RestController
public class TestController {
    @Autowired
    private ActiveMQTools activeMQTools;

    @RequestMapping("/sendmsg")
    public String sendMessageToActiveMQ(){
        activeMQTools.sendQueueMessage("aq:test","send message to activemq");
        return "success";
    }


    @JmsListener(destination = "aq:test")
    public void operationMessage(Object message) throws JMSException {
        ActiveMQTextMessage msg = (ActiveMQTextMessage) message;
        String xiaoxi = msg.getText();
        System.out.println("message:"+xiaoxi);
    }
}
